package arrays;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 区间和
 * User: Li_yizYa
 * Date: 2025—03—22
 * Time: 21:57
 */
public class Solution6 {
    /**
     * 普通方法（超时）
     * @param args
     */
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }

        while (scan.hasNextInt()) {
            int a = scan.nextInt();
            int b = scan.nextInt();
            int sum = 0;
            for (int i = a; i <= b; i++) {
                sum += arr[i];
            }
            System.out.println(sum);
        }
    }

    /**
     * 前缀和解法
     * @param args
     */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        int[] p = new int[n];
        int presum = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
            presum += arr[i];
            p[i] = presum;
        }

        while (scan.hasNextInt()) {
            int a = scan.nextInt();
            int b = scan.nextInt();
            int sum = 0;
            if (a == 0) {
                sum = p[b];
            } else {
                sum = p[b] - p[a - 1];
            }
            System.out.println(sum);
        }
    }
}
